<?php
/**
 * Created by PhpStorm.
 * User: Eric
 * Email: 13522679763@163.com
 * Date: 2018/3/5
 * Time: 20:00
 */

namespace app\admin\controller;

use Think\Controller;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

class Qiniu extends Basic
{
    public function getToken()
    {
        require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/vendor/qiniu/php-sdk/autoload.php');
        $auth = new Auth(config('accessKey'), config('secretKey'));
        $token = $auth->uploadToken(config('bucket'));
        $data['upToken'] = $token;
        $data['uptoken'] = $token;
        $data['domain'] = config('domain');
        json_success($data);
    }


    public function deleImg()
    {
        $key = input('post.key');
        $accessKey = 'vfJI3r3-k7dFAcXjEUpSLLozN5QyGp_OZvX8sFjS';
        $secretKey = 'tVtRSZf0gWXQy-2BKWkQlPPrFiAWVhlZ8oMvZ1Vv';
        $DOMAIN = 'http://p4qn0pwk6.bkt.clouddn.com/';
        $bucket = 'cdn-ids888';
        Vendor('Qiniusdk.autoload');
//        $key = "Fl_TwMNn4OqDAwT-7cnDwKZGkmLN";
        $auth = new Auth($accessKey, $secretKey);
        $config = new \Qiniu\Config();
        $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
        $err = $bucketManager->delete($bucket, $key);
        if ($err) {
            print_r($err);
        }

    }

}